package com.train.ticket.mapper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.train.common.model.page.PageSorted;
import com.train.common.resp.PageResp;
import com.train.resp.TicketPageResp;
import com.train.dto.TicketPageDTO;
import com.train.ticket.po.TicketPO;
import com.train.mybatis.base.MyBaseMapper;

import java.util.List;

/**
 * @author baitiaojun
 * @description 针对表【ticket(车票)】的数据库操作Mapper
 * @createDate 2025-03-14 15:17:16
 * @Entity generator.domain.Ticket
 */
public interface TicketMapper extends MyBaseMapper<TicketPO> {

    default PageResp<TicketPageResp> pageList(TicketPageDTO ticketPageDTO) {
        LambdaQueryWrapper<TicketPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ObjectUtil.isNotNull(ticketPageDTO.getMemberId()), TicketPO::getMemberId, ticketPageDTO.getMemberId());
        PageResp<TicketPO> ticketPOPageResp = this.selectPage(
                ticketPageDTO,
                queryWrapper, new PageSorted(TicketPO::getUpdateTime), new PageSorted(TicketPO::getCreateTime));
        List<TicketPageResp> ticketPageRespList = BeanUtil.copyToList(ticketPOPageResp.getData(), TicketPageResp.class);
        return new PageResp<>(ticketPOPageResp.getTotal(), ticketPageRespList);
    }
}